package controller.admin;
import Message.DTO.SetmealDTO;
import Message.DTO.SetmealPageQueryDTO;
import Message.PageResult;
import Message.Result;
import Message.vo.SetmealOverViewVO;
import Message.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import mapper.SetmealMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import service.SetmealService;

import java.util.List;

@Slf4j
@RequestMapping("/admin/setmeal")
@RestController
public class SetmealController {


    @Autowired
    SetmealService setmealService;

@GetMapping("/page")
public Result SelectPage(SetmealPageQueryDTO setmealPageQueryDTO){

            //调用Servoce层处理数据，返回SetmealOverViewVO格式的数据
    PageResult setmealOverViewVO = setmealService.SelectPage(setmealPageQueryDTO);
    log.info("setmealOverViewVO : {}", setmealOverViewVO);

    return Result.success(setmealOverViewVO);
}


    @PutMapping("")
    public Result UpdateSetmeal(@RequestBody SetmealDTO SetmealDTO){


    setmealService.UpdateSetmeal(SetmealDTO);




   return Result.success();


}@GetMapping("/{id}")
    public Result SelectById(@PathVariable Long id){


        SetmealVO setmealVO =   setmealService.SelectById(id);
          log.info("setmealDTO : {}", setmealVO);

          return Result.success(setmealVO);


    }



    @DeleteMapping("")
    public Result DeleteSetmeal(@RequestParam List<Long> ids){

    //调用Service层 完成删除操作
    setmealService.Delete(ids);
    return Result.success();

    }

    @PostMapping("")
    public Result AddSetmeal(@RequestBody SetmealDTO setmealDTO){

    //调用service完成新增操作
    setmealService.AddSetmeal(setmealDTO);

         return Result.success();
    }













}
